const koa = require('koa')
const bodyParser = require('koa-bodyparser');
const app = new koa()
app.use(bodyParser())
const config = require('./config')

// 挂载工程全局方法
require('./utils/index')

// 导入路由
const Interface  =  require('./router/index')
const routerKeys = Object.keys(Interface)


;(async() => {
  // 注册路由
  await routerKeys.forEach(item => {
    app.use(Interface[item].routes()).use(Interface[item].allowedMethods())
  })
  $log.success('路由挂载成功')
  await app.listen(config.service.port, config.service.host, err => {
    if (err) return $log.error('server端工程启动失败：' + err)
    $log.success(`server端工程启动成功： http://${config.service.host}:${config.service.port}`)
  })
})()